<?
require_once 'config.inc.php';
if (empty($_SESSION["username"])){
	header("Location:./admin/login.php");
}

$uid = $_SESSION["uid"];
if ($_POST){
 
	$keywords=$_POST['keywords'];
	if($keywords &&  strstr($keywords,'TAG:')){//搜索TAG
		$keywords2 = str_replace('TAG:','',$keywords);
		$ssql1=" AND (a.keywords like '%$keywords2,%' OR a.keywords like '$keywords2')";	
	}else{
		$ssql1=" AND a.title like '%$keywords%' or a.content like '%$keywords%'";
	}
	
	$ssql2=" AND a.sitename like '%$keywords%' or a.url like '%$keywords%' or a.info like '%$keywords%'";
	$ssql3=" AND a.who like '%$keywords%' or a.mobile like '%$keywords%' or a.xiao like '%$keywords%' or a.email like '%$keywords%' or a.qq like '%$keywords%' or a.msn like '%$keywords%'  or a.office like '%$keywords%' or a.home like '%$keywords%' or a.info like '%$keywords%' ";
	$ssql4=" AND a.content like '%$keywords%' ";

	$order_by = $_POST['order_by'];
}else{
	$order_by = 1;
}

if(0 < $_REQUEST['limit']){
	$limit = $_SESSION['limit'] = $_REQUEST['limit'];
}else{
	if(isset( $_SESSION['limit'])){
		$limit = $_SESSION['limit'] ;
	}else{	
		$limit =  20 ;
	}
}

if($order_by==1){
	$order_by_sql ='order by update_time desc';//修改日期
}elseif($order_by==2){
	$order_by_sql ='order by hit desc';
}else{
	$order_by_sql ='order by create_time desc';//创建日期
}

$notes = $sites = $adds= $blogs =array();
$sql = "SELECT a.*,b.name  FROM {$tablepre}note as a left join {$tablepre}channel as b  on a.cid = b.id  WHERE a.uid='$uid' $ssql1 $order_by_sql LIMIT $limit ";
$result=mysql_query($sql); 
while($note = mysql_fetch_array($result,MYSQL_ASSOC)) {
	$notes[]=$note;
}

$sql = "SELECT a.*,b.name  FROM {$tablepre}sites  as a left join {$tablepre}channel as b  on a.cid = b.id  WHERE a.uid='$uid' $ssql2 $order_by_sql LIMIT $limit ";
$result=mysql_query($sql); 
while($site = mysql_fetch_array($result,MYSQL_ASSOC)) {
	$sites[]=$site;
}
 
$sql = "SELECT a.*,b.name FROM {$tablepre}adds  as a left join {$tablepre}channel as b  on a.cid = b.id  WHERE a.uid='$uid' $ssql3 $order_by_sql LIMIT $limit ";
$result=mysql_query($sql); 
while($add = mysql_fetch_array($result,MYSQL_ASSOC)) {
	$adds[]=$add;
}
 
$sql = "SELECT a.*,b.name FROM {$tablepre}blog  as a left join {$tablepre}channel as b  on a.cid = b.id  WHERE a.uid='$uid' $ssql4 $order_by_sql LIMIT $limit ";
$result=mysql_query($sql); 
while($blog = mysql_fetch_array($result,MYSQL_ASSOC)) {
	$blog['content'] = strip_tags($blog['content']);
	$blog['content'] = mb_strcut($blog['content'],0,60,'utf-8');
	$blogs[]=$blog;
}
 
 
//统计tags

$sql = "SELECT keywords  FROM {$tablepre}note WHERE keywords is not null AND keywords !='' AND uid='$uid'";
$query=mysql_query($sql); 
$keywordss = array();
while($result = mysql_fetch_array($query,MYSQL_ASSOC)) {
	$keywordss[]=$result['keywords'];
}

$keys =array();
foreach($keywordss as $k=>$v){
	$v = trim($v,',');
	$v = explode(',',$v);
	foreach($v as $kk=>$vv){
		$keys[$vv]++;
	}
}

//update_keywords();
//更新所有文章的tag
function update_keywords(){
	global $tablepre;
	$sql = "SELECT count(id) as count  FROM {$tablepre}note";
	$query=mysql_query($sql); 
	$result = mysql_fetch_array($query,MYSQL_ASSOC);
	pecho($result['count']);
	
	$sql = "SELECT count(id) as count  FROM {$tablepre}note WHERE keywords =''";
	$query=mysql_query($sql); 
	$result = mysql_fetch_array($query,MYSQL_ASSOC);
	pecho($result['count']);
	
	
	$sql = "SELECT id,content,keywords  FROM {$tablepre}note WHERE keywords ='' ORDER BY ID LIMIT 200";
	
	$query=mysql_query($sql); 
	while($result = mysql_fetch_array($query,MYSQL_ASSOC)) {
		if(!$result['keywords']){
			$content = $result['content'];
			$ke = get_keywords(strip_tags($content));
			$ids[$result['id']]=$ke;
			pecho('id:'.$result['id'].' keywords:'.$ke);
			flush(); 
		}
	}
	if($ids){
		foreach($ids as $k=>$v){
			if(!strstr($v,'://')){
				$sql = "UPDATE {$tablepre}note SET keywords = '$v' WHERE id = $k LIMIT 1";
				mysql_query($sql);
			}
			
		}
	}
}


/*pecho($keywords);
pecho($keys);
arsort ($keys);
pecho($keys);*/


?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0041)http://group.zol.com.cn/frmView_right.php -->
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<META content="MSHTML 6.00.2900.3199" name=GENERATOR>
<link href="images/style.css" rel="stylesheet" type="text/css">
<script>
function bb(){
alert('this bb');
}
</script>
</HEAD>
<BODY>
<TABLE 
style="BORDER-RIGHT: #557bb9 1px solid; BORDER-TOP: #557bb9 1px solid; MARGIN-TOP: 8px; MARGIN-BOTTOM: 6px; BORDER-LEFT: #557bb9 1px solid; BORDER-BOTTOM: #557bb9 1px solid" 
cellSpacing=0 cellPadding=0 width="96%" align=center border=0>
  <TBODY>
  <TR>
    <TD>
      <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
        <TBODY>
        <TR>
          <TD class=pl10 bgColor=#d2def2 height=26>
		  <form action="" method="post"> 
<!--		    <label>
                <input name="stype" type="radio" value="note" checked>
                资料</label>

              <label>
                <input type="radio" name="stype" value="site">
                网址</label>

              <label>
                <input type="radio" name="stype" value="blog">
                日记</label>

              <label>
                <input type="radio" name="stype" value="adds">
                通讯录</label>
--> &nbsp; &nbsp; <input name="keywords" type="text" id="keywords" value="<?php echo $keywords ?>">
            显示：<input name="limit" type="text" value="<?php echo $limit ?>" size="4">
            条
            <select name="order_by">
              <option value="0" <?php echo $order_by==0?'selected':''?> >创建日期</option>
              <option value="1" <?php echo $order_by==1?'selected':''?> >修改日期</option>
              <option value="2"  <?php echo $order_by==2?'selected':''?> >访问次数</option>
            </select>
            <input name="" type="submit" value=搜索></form></TD>
        </TR>
        <TR>
          <TD height=110>
 
<div id=index>		
		<dl class=notes>
		<dt><strong>资料</strong> <span><a href="./admin/admin_note.php">添加</a></span></dt>
		<?php 
		 foreach( $notes as $note ) {?>
		 <dd><a title="分类：<?php echo  $note[name] ?>" href="view_note.php?id=<?php echo $note[id] ?>"><?php echo  $note[title] ?>:<?php echo  $note[hit] ?></a><em><?php echo format_date('m/d/y H:i','',$note[update_time])  ?></em></dd>
		 <?php  } ?>
		 </dl>
		 <dl class=sites>
		<dt><span><a href="./admin/admin_site.php">添加</a></span><strong>网站</strong></dt>
		<?php 
		 foreach( $sites as $note ) {?>
		 <dd> <a title="<?php echo "分类：$note[name] <br> 详细： $note[info] " ?>" href="view_site.php?id=<?php echo $note[id] ?>"><?php echo  $note[sitename] ?></a><em><a target=_blank href="<?php echo $note[url] ?>">打开网站</a></em></dd>
		 <?php  } ?>
		 </dl>
		 <dl class=blogs>
		<dt><strong>日志</strong><span><a href="./admin/admin_blog.php">添加</a></span></dt>
		<?php 
		 foreach( $blogs as $note ) {?>
		 <dd><a href="view_blog.php?id=<?php echo $note[id] ?>"><?php echo  $note[content] ?></a><?php echo format_date('m/d/y H:i','',$note[create_time])  ?></dd>
		 <?php  } ?>
		 </dl>
		 
		 
		 
		  <dl class=adds>
		<dt><strong>通讯</strong><span><a href="./admin/admin_adds.php">添加</a></span></dt>
		<?php 
		 foreach( $adds as $note ) {
		
		 
//$note[who] ? $str =','.$note[who]:0;
unset($arr );
$arr[] = $note[mobile];
$arr[] = $note[xiao];
$arr[] = $note[email] ;
$arr[] = $note[qq] ;
$arr[] = $note[msn] ;
$arr[] = $note[office];
$arr[] = $note[home] ;
$arr[] = $note[info];

$arr= array_filter($arr); 
$str = implode(',',$arr);
$str = substr2($str,0,38);
		 ?>
		 <dd><a title="分类：<?php echo  $note[name] ?>" href="view_adds.php?id=<?php echo $note[id] ?>"><?php echo  $note[who] ?></a> <?php echo $str?></dd>
		 <?php  } ?>
		 </dl>
		 
		  
		 </div>
          <div id="tags_box"><DIV id="TAGS">
          <ul>
          <?php 
		  
		 foreach( $keys as $k=>$v ) {?>
		 <li><a title="TAG：<?php echo  $k ?>" href="javascript:top.show_tags('<?php echo $k  ?>')"><?php echo $k  ?><em>(<?=$v?>)</em></a></li>
		 <?php  } ?>
         </ul>
          </DIV></div>
          <script>
		  top.switch_tags(document);
		  setInterval('top.switch_tags(document,true);',60000);
		  </script>        
         
		  		  </TD>
        </TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
</BODY></HTML>
